# Compiler settings
CXX = g++
CXXFLAGS = -std=c++11 -I.

# Phony targets
.PHONY: all clean report run B C D E F

# Default target
all: B C D E F report

HEADS = Function.hpp EquationSolver.hpp

# OS Check
ifeq ($(OS),Windows_NT)
    TARGET_EXT = .exe
else
    TARGET_EXT =
endif

# Rule for B
B: B.cpp $(HEADS)
	$(CXX) $(CXXFLAGS) -o B$(TARGET_EXT) B.cpp
	./B$(TARGET_EXT) > output_B.txt

# Rule for C
C: C.cpp $(HEADS)
	$(CXX) $(CXXFLAGS) -o C$(TARGET_EXT) C.cpp
	./C$(TARGET_EXT) > output_C.txt

# Rule for D
D: D.cpp $(HEADS)
	$(CXX) $(CXXFLAGS) -o D$(TARGET_EXT) D.cpp
	./D$(TARGET_EXT) > output_D.txt

# Rule for E
E: E.cpp $(HEADS)
	$(CXX) $(CXXFLAGS) -o E$(TARGET_EXT) E.cpp
	./E$(TARGET_EXT) > output_E.txt

# Rule for F
F: F.cpp $(HEADS)
	$(CXX) $(CXXFLAGS) -o F$(TARGET_EXT) F.cpp
	./F$(TARGET_EXT) > output_F.txt

# Compile the report
report:
	xelatex report.tex

# Run all B, C, D, E, F in sequence
run: B C D E F

# Clean target
clean:
	rm -f *.o *.exe *.aux *.log *.gz *.pdf *.txt *.out
